package com.xiaotu.spider.maoyan.pageprocessor;

import java.math.RoundingMode;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.xiaotu.common.exception.SpiderException;
import com.xiaotu.common.exception.SpiderExceptionCode;
import com.xiaotu.common.model.MaoYanBoxofficeModel;
import com.xiaotu.common.model.MaoYanMaterielsModel;
import com.xiaotu.common.model.MaoYanMovieBasicInfoModel;
import com.xiaotu.common.model.MaoYanMovieBoxDetailModel;
import com.xiaotu.common.model.MaoYanMovieCityModel;
import com.xiaotu.common.model.MaoYanMovieMarketModel;
import com.xiaotu.common.model.MaoYanMoviePeopleModel;
import com.xiaotu.common.model.MaoYanMovieRecordLineModel;
import com.xiaotu.common.model.MaoYanMovieScoreRelateModel;
import com.xiaotu.common.model.MaoYanMovieShadowModel;
import com.xiaotu.common.model.MaoYanMovieSplitModel;
import com.xiaotu.common.util.Constants;
import com.xiaotu.common.util.DateUtils;
import com.xiaotu.common.util.GsonUtils;
import com.xiaotu.common.util.HtmlUtil;
import com.xiaotu.common.util.PageUtils;
import com.xiaotu.common.util.PropertiesUtil;
import com.xiaotu.common.util.RegexUtils;
import com.xiaotu.common.util.SepratorUtil;
import com.xiaotu.common.util.StringUtil;
import com.xiaotu.common.util.UUIDUtils;
import com.xiaotu.server.service.maoyan.MaoYanMovieBasicInfoService;
import com.xiaotu.spider.AUrlPageProcessor;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.selector.Html;

/***
 * 猫眼相关数据：
 * 昨日票房（每天采集）
 * 想看画像（下线采集）
 * 城市票房（下线采集）
 * 影投票房（下线采集）
 * 营销事件（下线采集）
 * 分账票房（下线采集）
 * 猫眼评分（下线采集）
 * 票房明细（下线采集）
 * 物料相关（下线采集）
 * @author Mr.zhang
 *
 */
@Component("MaoYanMovieRelatedDataPageProcessor")
public class MaoYanMovieRelatedDataPageProcessor extends AUrlPageProcessor {

	
	private Map<String,String> cookies = new HashMap<String,String>();
	
	{
		cookies.put("Cookie", PropertiesUtil.getProperty("BoxOffice.site.Cookie"));
	}
	
	private final String regex = "[0-9]{0,}[-]{0,}[0-9]{0,}";
	
	public static final String START_URL = "https://www.baidu.com/";//初始url
	
	public static final String YESTERDAY_BOX_URL = "http://piaofang.maoyan.com/dashboard-ajax/movie?showDate=%s&orderType=0";//昨日票房
	
	private String CITY_URL = "http://piaofang.maoyan.com/movie/%s/box-ajax?boxLevel=4&date=%s&offset=0&type=areaBox&method=change";//分城票房	获取下映当天的数据

    private String SHADOW_URL = "http://piaofang.maoyan.com/movie/%s/box-ajax?boxLevel=5&date=%s&offset=0&type=shadowBox&method=change";//影投票房	获取下映当天的数据

    public static final String PEOPLE_URL = "https://piaofang.maoyan.com/movie/%s/wantindex?wkwebview=1&city_tier=0&city_id=0&cityName=全国";//受众票房

    public static final String DETAIL_URL = "http://piaofang.maoyan.com/movie/%s?_v_=yes";//详细页面

    public static final String MARKET_URL = "http://piaofang.maoyan.com/movie/%s/marketing";//营销事件
    
    public static final String BOX_DETAIL_URL = "https://piaofang.maoyan.com/movie/%s/boxshow";//日期票房（票房明细）
    
    public static final String MATERIELS_URL = "https://piaofang.maoyan.com/movie/%s/promotion/trailers";//物料统计
    
    private List<Object> offLineList = null;
    
    private Object existMap = null;
    
    private String yesterdayDate = DateUtils.getSpecifiedDayBefore(
    		DateUtils.getDateString(new Date(), DateUtils
    	            .FILE_NOMENCLATURE_FORMAT),DateUtils
            .FILE_NOMENCLATURE_FORMAT);
    
    @Autowired
    private MaoYanMovieBasicInfoService maoYanMovieBasicInfoService;
    
	@Override
	public void process(Page page) {
		
		Map<String, Object> extrasMap = page.getRequest().getExtras();
		
		switch (this.getPageDataType(page))
        {
            case Constants.PageDataType.TV_RECORD:
                this.detailProcess(page,extrasMap);
                break;
            case Constants.PageDataType.TV_CITY:
                this.cityProcess(page,extrasMap);
                break;
            case Constants.PageDataType.MOVIE_COMPANY:
                this.companyProcess(page,extrasMap);
                break;
            case Constants.PageDataType.TV_AUDIENCE:
                this.peopleProcess(page,extrasMap);
                break;
            case Constants.PageDataType.MOVIE_MARKET:
                this.marketProcess(page,extrasMap);
                break;
            case Constants.PageDataType.TV_COMMENT:
            	this.getScoreDetailInfo(page,extrasMap);
            	break;
            case Constants.PageDataType.MOVIE_BOX_DETAIL:
            	this.getMovieBoxDetail(page,extrasMap);
            	break;
            case Constants.PageDataType.MOVIE_MATERIELS:
            	this.getMovieMateriels(page,extrasMap);
            	break;
            case Constants.PageDataType.MOVIE_BOX:
            	this.yestodayProcess(page);
            	break;
            default:
            	this.addRequestProcess(page);
            	break;
        }
	}
	

	private void addRequestProcess(Page page) {
		
		//添加昨日票房请求
		PageUtils.addTargetRequest(page,String.format(YESTERDAY_BOX_URL, yesterdayDate),null);
		
		//添加已下映其他相关请求  开始。。。。
    	this.getMovieOffLineList();
  		for(Object model : offLineList){
  			MaoYanMovieRecordLineModel realModel = (MaoYanMovieRecordLineModel)model;
  			String dataId = realModel.getDataid();
  			String tvid = realModel.getTvid();
  			String tvname = realModel.getTvname();
  			
  			long offlineDate = getSecondsFromDate(convertDateToDate(realModel.getOffline_date()));
  			long offlineAfterDate = getSecondsFromDate(convertDateToDate(DateUtils.getSpecifiedDayAfterDate(
				convertDateStr(realModel.getOffline_date()),DateUtils
		            .FILE_NOMENCLATURE_FORMAT)));
  			
  			Map<String,Object> paramMap = new HashMap<String,Object>();
  			paramMap.put("dataId", dataId);
  			paramMap.put("tvid", tvid);
  			paramMap.put("tvname", tvname);
  			paramMap.put("offlineDate", offlineDate);
  			paramMap.put("offlineAfterDate", offlineAfterDate);
  		    Stream.of(SHADOW_URL, CITY_URL, DETAIL_URL, PEOPLE_URL, MARKET_URL , BOX_DETAIL_URL , MATERIELS_URL).forEach(url ->
              PageUtils.addTargetRequest(page, String.format(url, dataId,convertDateStr(realModel.getOffline_date())), paramMap));
  		}
  		//添加已下映其他相关请求 结尾。。。。
	}

	//电影物料统计
	private void getMovieMateriels(Page page, Map<String, Object> extrasMap) {
		String dataId = extrasMap.get("dataId").toString();
		String tvName = extrasMap.get("tvname").toString();
		long offlineAfterDate = Long.parseLong(extrasMap.get("offlineAfterDate").toString());
		String url = page.getRequest().getUrl();
		Html html = page.getHtml();
		if(null == html.xpath("//div[@class='promotion-content']").get())
			throw new SpiderException(SpiderExceptionCode.DataInvalideException);
		if(url.contains(dataId)){
			//物料总数
			String materielsNum = html.xpath("//div[@class='promotion-content']//div[@class='tralier']//div[@class='tralier-number']//"
					+ "div[@class='value-style']//text()").get();
			//总播放量
			String totalPlayNum = HtmlUtil.delHTMLTag(html.xpath("//div[@class='promotion-content']//div[@class='tralier']//div[@class='play-number']//"
					+ "div[@class='value-style']//text()").get());
			String playUnit = HtmlUtil.delHTMLTag(html.xpath("//div[@class='promotion-content']//div[@class='tralier']//div[@class='play-number']//"
					+ "div[@class='value-style']//span[@class='unit']//text()").get());
			if(totalPlayNum!=null){
				totalPlayNum = totalPlayNum+playUnit;
			}
			
			//总评论数
			String totalCommentsNum = html.xpath("//div[@class='promotion-content']//div[@class='tralier']//div[@class='comment-number']//"
					+ "div[@class='value-style']//text()").get();
			if(null != totalCommentsNum && StringUtils.isNotBlank(totalCommentsNum)){
				totalCommentsNum = HtmlUtil.delHTMLTag(totalCommentsNum);
			}
			
			String commentUnit = html.xpath("//div[@class='promotion-content']//div[@class='tralier']//div[@class='comment-number']//"
					+ "div[@class='value-style']//span[@class='unit']//text()").get();
			if(null != commentUnit && StringUtils.isNotBlank(commentUnit)){
				commentUnit = HtmlUtil.delHTMLTag(commentUnit);
			}
			if(totalCommentsNum!=null){
				totalCommentsNum = totalCommentsNum+commentUnit;
			}
			
			MaoYanMaterielsModel maoYanMaterielsModel = new MaoYanMaterielsModel(
					null,tvName,dataId,Constants.SiteName.MAOYAN,
					StringUtil.nullToString(materielsNum),
					StringUtil.nullToString(totalPlayNum),
					StringUtil.nullToString(totalCommentsNum)
					);
			//更新下映时间为采集时间
			maoYanMaterielsModel.setCollectTime(offlineAfterDate);
			page.putField(MaoYanMaterielsModel.class.getName(), maoYanMaterielsModel);
		}
	}

	//电影票房明细
	private void getMovieBoxDetail(Page page, Map<String, Object> extrasMap) {
		String dataId = extrasMap.get("dataId").toString();
		String tvName = extrasMap.get("tvname").toString();
		long offlineAfterDate = Long.parseLong(extrasMap.get("offlineAfterDate").toString());
		String url = page.getRequest().getUrl();
		if(url.contains(dataId)){
			//解密加密数据
			Html html = PageUtils.spiderAudienceRating(page,cookies);
			List<String> dateList = html.xpath("//section[@class='table-wrapper']//div[@class='t-table-wrapper']"
					+ "//div[@class='t-table']//div[@class='t-row']//div[@class='t-col']//span").all();
			
			List<String> boxList = html.xpath("//section[@class='table-wrapper']//div[@class='t-other-col t-scroller']"
					+ "//div[@class='t-change-wrapper']//div[@class='t-change']//div[@class='t-row']").all();
			List<MaoYanMovieBoxDetailModel> maoYanMovieBoxDetailList = new ArrayList<MaoYanMovieBoxDetailModel>();
			if(dateList.size() == boxList.size() && dateList.size()>0 && boxList.size()>0){
				for(int i=0;i<dateList.size();i++){
					String str = HtmlUtil.delHTMLTag(dateList.get(i));
					String weekSplit = str.substring(str.indexOf("周"), str.indexOf("周")+2);
					String [] tempDateArr = HtmlUtil.delHTMLTag(dateList.get(i)).split(weekSplit);
					Html boxHtml = new Html(boxList.get(i));
					List<String> all = boxHtml.xpath("//div[@class='t-row']//div[@class='t-col']//i[@class='cs']//text()").all();
					if(null == tempDateArr || null==all || tempDateArr.length!=2 || all.size()!=17)
						throw new SpiderException(SpiderExceptionCode.DataInvalideException);
					MaoYanMovieBoxDetailModel maoYanMovieBoxDetailModel = new MaoYanMovieBoxDetailModel(
							null,tvName,dataId,Constants.SiteName.MAOYAN,
							tempDateArr[0],weekSplit,tempDateArr[1].trim(),
							all.get(0)+"万",all.get(1),all.get(2),all.get(3),
							all.get(4),all.get(5),all.get(6),all.get(7),
							all.get(8),all.get(9),all.get(10),all.get(11),
							all.get(12),all.get(13),all.get(14)+"万",all.get(15),
							all.get(16)
							);
					//更新下映时间为采集时间
					maoYanMovieBoxDetailModel.setCollectTime(offlineAfterDate);
					maoYanMovieBoxDetailList.add(maoYanMovieBoxDetailModel);
				}
				page.putField(MaoYanMovieBoxDetailModel.class.getName(), maoYanMovieBoxDetailList);
			}
		}
		
	}

		
	@SuppressWarnings("null")
	private void detailProcess(Page page,Map<String, Object> extrasMap){
		
		String dataId = extrasMap.get("dataId").toString();
		String tvname = extrasMap.get("tvname").toString();
		long offlineAfterDate = Long.parseLong(extrasMap.get("offlineAfterDate").toString());
		//解密数据
        Html html = PageUtils.spiderAudienceRating(page,cookies);
        //猫眼评分
        String score = null;
        String starLevel = null;
        String cinemaScore = null;//观众评分人数
        String wantToSee = null;//想看人数
        String otherScoreName = null;//其他评分来源
        String otherScoreValue = null;//其他来源评分
        
        //票房相关
        String totalBoxoffice = null;// 累计票房
        String firstDayBoxoffice = null;// 首日票房
        String firstWeekBoxoffice = null;// 首周票房
        String forecastBoxoffice = null;// 预测票房
        String boxoffice = null; // 分账总票房
        String productionBox = null;//片方票房
        String cinemaBox = null;//影院票房
        String otherBox = null;//其他票房
        
        List<String> checkDataList = new ArrayList<String>();
        
        try {
			
        	List<String> starLevelList = new ArrayList<String>();
        	List<String> ratingStarsDivList = html.xpath("//div[@class='rating-stars']").all();
        	if(ratingStarsDivList.size()>0){
        		List<String> starsList = new Html(ratingStarsDivList.get(0)).xpath("//div[@class='rating-stars']//span").all();
        		//是否存在评分数据
                if(starsList.size()==6){
                	for(int i = 0;i<starsList.size();i++ ){
                    	Html starHtml = new Html(starsList.get(i));
                    	if(starHtml.xpath("//span//@class").get().equals("rating-num")){
                    		score = HtmlUtil.delHTMLTag(starHtml.xpath("//span").get());
                    	}else{
                    		starLevelList.add(HtmlUtil.delHTMLTag(starHtml.xpath("//span//@class").get()));
                    	}
                    }
                }
        	}
            
            if(starLevelList.size() == 5){
            	starLevel = getStarLevel(starLevelList);
            }
            
            cinemaScore = html.xpath("//div[@class='score-detail']//p[@class='detail-score-count']//text()").get();
            if(StringUtils.isNotBlank(cinemaScore)){
            	cinemaScore = cinemaScore.replace("观众评分","").trim();
            }
            wantToSee = html.xpath("//div[@class='score-detail']//p[@class='detail-wish-count']//text()").get();
            if(StringUtils.isBlank(wantToSee)){//重新获取
            	wantToSee = html.xpath("//div[@class='block-wish-item left']//h2//text()").get();
            	if(wantToSee.contains("暂无想看")){
            		wantToSee = null;
            	}
            }
            if(StringUtils.isNotBlank(wantToSee)){
            	wantToSee = wantToSee.replace("人想看","").trim();
            }
            String otherScoreStr = html.xpath("//div[@class='score-detail']//p[@class='detail-other-score']//text()").get();
            if(null != otherScoreStr){
            	String [] otherScoreArr = otherScoreStr.replace("其他评分 : ","").split(" ");
            	otherScoreName = otherScoreArr[0];
                otherScoreValue = otherScoreArr[1];
            }
            
            
            
            //累计票房相关
            checkDataList = html.xpath
            		("//div[@class='movie-container']//div[@class='info-detail-row']").all();
            if (checkDataList.size()==0)
                throw new SpiderException(SpiderExceptionCode.DataInvalideException);
            
            String boxOfficeLine =html.xpath
            		("//div[@class='movie-container']//div[@class='info-detail-row']").all().get(0);
            Html htmlUp = new Html(boxOfficeLine);
            List<String> allUp = htmlUp.xpath("//div[@class='info-detail-row']//div").all();
            if(new Html(allUp.get(0)).xpath("//p[@class='info-detail-title']").get().trim().contains("累计票房")){
            	totalBoxoffice = getFormattedData(new Html(allUp.get(0)).xpath("//p[@class='info-detail-content']").get()).replace("--", "").replace("暂无", "");
            }
            if(new Html(allUp.get(2)).xpath("//p[@class='info-detail-title']").get().trim().contains("首日票房")){
            	firstDayBoxoffice = getFormattedData(new Html(allUp.get(2)).xpath("//p[@class='info-detail-content']").get()).replace("--", "").replace("暂无", "");
            }
            if(new Html(allUp.get(4)).xpath("//p[@class='info-detail-title']").get().trim().contains("首周票房")){
            	firstWeekBoxoffice = getFormattedData(new Html(allUp.get(4)).xpath("//p[@class='info-detail-content']").get()).replace("--", "").replace("暂无", "");
            }
            if(new Html(allUp.get(6)).xpath("//p[@class='info-detail-title']").get().trim().contains("预测票房")){
            	forecastBoxoffice = getFormattedData(new Html(allUp.get(6)).xpath("//p[@class='info-detail-content']").get()).replace("--", "").replace("暂无", "");
            }
            
            
            
            //分账票房相关
            String boxOffice =html.xpath
            		("//div[@class='movie-container']//div[@class='info-detail-row']").all().get(1);
            Html htmls = new Html(boxOffice);
            List<String> all = htmls.xpath("//div[@class='info-detail-row']//div").all();
            if (all == null || all.size() < 8 || StringUtils.isEmpty(boxOffice) || allUp == null || allUp.size() < 7 || StringUtils.isEmpty(boxOfficeLine))
                throw new SpiderException(SpiderExceptionCode.DataInvalideException);
            
            if(new Html(all.get(0)).xpath("//p[@class='info-detail-title']").get().trim().contains("分账票房")){
            	boxoffice = getFormattedData(new Html(all.get(0)).xpath("//p[@class='info-detail-content']").get()).replace("--", "").replace("暂无", ""); 
            }
            if(new Html(all.get(3)).xpath("//p[@class='info-detail-title']").get().trim().contains("片方")){
            	productionBox = getFormattedData(new Html(all.get(3)).xpath("//p[@class='info-detail-content']").get()).replace("--", "").replace("暂无", "");
            }
            if(new Html(all.get(5)).xpath("//p[@class='info-detail-title']").get().trim().contains("影院")){
            	cinemaBox = getFormattedData(new Html(all.get(5)).xpath("//p[@class='info-detail-content']").get()).replace("--", "").replace("暂无", "");
            }
            if(new Html(all.get(7)).xpath("//p[@class='info-detail-title']").get().trim().contains("其他")){
            	otherBox = getFormattedData(new Html(all.get(7)).xpath("//p[@class='info-detail-content']").get()).replace("--", "").replace("暂无", "");
            }
		} catch (Exception e) {
			System.out.println("当前数据id:"+dataId+"电影名称:"+tvname+"-----------"+MaoYanMovieRelatedDataPageProcessor.class.getName()+" detailProcess() "+e.getMessage());
		}
        
        MaoYanMovieScoreRelateModel maoYanMovieScoreRelateModel = new MaoYanMovieScoreRelateModel(
        		null,tvname,dataId,Constants.SiteName.MAOYAN,
        		null,null,null,null,null,null,null,null,null,
        		starLevel,score,cinemaScore,wantToSee,otherScoreName,otherScoreValue
        		);
        //更新下映时间为采集时间
        maoYanMovieScoreRelateModel.setCollectTime(offlineAfterDate);
        extrasMap.put("maoYanMovieScoreRelateModel", maoYanMovieScoreRelateModel);
        //获取评分详细信息
        PageUtils.addTargetRequest(page, String.format("https://piaofang.maoyan.com/movie/%s/audienceRating?usePageCache=true", dataId), extrasMap);
        
        if(null != checkDataList && checkDataList.size()>0){
        	MaoYanMovieSplitModel maoYanMovieSplitModel = new MaoYanMovieSplitModel(
        			null,
            		extrasMap.get("tvname").toString(),
            		RegexUtils.regexSearch
                    (RegexUtils.REGEX_INTEGER, page.getUrl().toString()),
                    Constants.SiteName.MAOYAN,
                    totalBoxoffice,
                    firstDayBoxoffice,
                    firstWeekBoxoffice,
                    forecastBoxoffice,
                    boxoffice, 
                    productionBox, 
                    cinemaBox,
                    otherBox);
        	//更新下映时间为采集时间
        	maoYanMovieSplitModel.setTimestamp(offlineAfterDate);
        	page.putField(MaoYanMovieSplitModel.class.getName(),maoYanMovieSplitModel);
        }
        
	}	
	
	
	private void getScoreDetailInfo(Page page,Map<String, Object> extrasMap){
		String dataId = extrasMap.get("dataId").toString();
		MaoYanMovieScoreRelateModel maoYanMovieScoreRelateModel = (MaoYanMovieScoreRelateModel) extrasMap.get("maoYanMovieScoreRelateModel");
		String url = page.getRequest().getUrl();
		//解密加密数据
		Html html = PageUtils.spiderAudienceRating(page,cookies);
		if(url.contains(dataId)){
			//观众热评词
			String hotComments = "";
			//{9-10分,7-8分，5-6分，3-4分，1-2分}
			String [] scoreNames = null;
			String [] scoreRates = null;
			//{男，女}
			String [] sexNames = null;
			String [] sexScores = null;
			//{20岁以下，20-24岁，25-29岁，30-34岁，35-39岁，40岁以上}
			String [] ageNames = null;
			String [] ageScores = null;
			//{一线城市，二线城市，三线城市，四线城市}
			String [] areaNames = null;
			String [] areaScores = null;
			List<String> all = html.xpath("//section[@class='movie-comments']//div[@class='movie-tags']//span").all();
			if(all.size()>0){
				for(int i=0;i<all.size();i++){
					Html spanHtml = new Html(all.get(i));
					hotComments += ","+spanHtml.xpath("//span//text()").get();	
				}
				hotComments = hotComments.substring(1);
			}
			
			List<String> distributeItemList = html.xpath("//section[@class='movie-comments']//div[@class='distribute-chart']//div[@class='distribute-item']").all();
			String[][] scoreNameRatesArr = getScoreNameRates(distributeItemList,"score");
			if(null != scoreNameRatesArr){
				scoreNames = scoreNameRatesArr[0];
				scoreRates = scoreNameRatesArr[1];
			}
			List<String> sexItemList = html.xpath("//section[@class='persona-section']//div[@class='persona-gender']//div[@class='persona-gender-item']").all();
			String[][] sexNameRatesArr = getScoreNameRates(sexItemList,"sex");
			if(null != sexNameRatesArr){
				sexNames = sexNameRatesArr[0];
				sexScores = sexNameRatesArr[1];
			}
			List<String> ageItemList = html.xpath("//section[@class='persona-section']//div[@class='persona-block persona-block-yellow']//div[@class='persona-item']").all();
			String[][] ageNameRatesArr = getScoreNameRates(ageItemList,"age");
			if(null != ageNameRatesArr){
				ageNames = ageNameRatesArr[0];
				ageScores = ageNameRatesArr[1];
			}
			List<String> cityItemList = html.xpath("//section[@class='persona-section']//div[@class='persona-block persona-block-blue']//div[@class='persona-item']").all();
			String[][] cityNameRatesArr = getScoreNameRates(cityItemList,"city");
			if(null != cityNameRatesArr){
				areaNames = cityNameRatesArr[0];
				areaScores = cityNameRatesArr[1];
			}
			maoYanMovieScoreRelateModel.setHotComments(hotComments);
			maoYanMovieScoreRelateModel.setScoreNames(scoreNames);
			maoYanMovieScoreRelateModel.setScoreRates(scoreRates);
			maoYanMovieScoreRelateModel.setSexNames(sexNames);
			maoYanMovieScoreRelateModel.setSexScores(sexScores);
			maoYanMovieScoreRelateModel.setAgeNames(ageNames);
			maoYanMovieScoreRelateModel.setAgeScores(ageScores);
			maoYanMovieScoreRelateModel.setAreaNames(areaNames);
			maoYanMovieScoreRelateModel.setAreaScores(areaScores);
			
			page.putField(MaoYanMovieScoreRelateModel.class.getName(), maoYanMovieScoreRelateModel);
			
		}
	}
	
	
	private String[][] getScoreNameRates(List<String> list,String flag){
		if(list.size()==0){
			return null;
		}
		String [][] scoreNameRatesArr = new String[2][list.size()];
		for(int i =0;i<list.size();i++){
			Html html = new Html(list.get(i));
			String key = null;
			String value = null;
			switch (flag){
				case "score":
					key = html.xpath("//div[@class='distribute-item']//div[@class='distribute-label']//text()").get().trim();
					value = formatDouble3(Double.parseDouble(html.xpath("//div[@class='distribute-item']//div[@class='distribute-bar-bg']//span[@class='distribute-val']//text()").get().trim().replace("%", ""))/100);
				break;
				case "sex":
					key = html.xpath("//div[@class='persona-gender-item']//div[@class='persona-item-key']//text()").get().trim();
					value = html.xpath("//div[@class='persona-gender-item']//div[@class='persona-item-value']//i[@class='cs']//text()").get().trim().replace("分", "");
					break;
				case "age":
					key = html.xpath("//div[@class='persona-item']//div[@class='persona-item-key']//text()").get().trim();
					value = html.xpath("//div[@class='persona-item']//div[@class='persona-item-value']//i[@class='cs']//text()").get().trim().replace("分", "");
					break;
				case "city":
					key = html.xpath("//div[@class='persona-item']//div[@class='persona-item-key']//text()").get().trim();
					value = html.xpath("//div[@class='persona-item']//div[@class='persona-item-value']//i[@class='cs']//text()").get().trim().replace("分", "");
					break;	
			}
			
			scoreNameRatesArr[0][i] = key; 
			scoreNameRatesArr[1][i] = value; 
		}
		return scoreNameRatesArr;
	}
	
	private String formatDouble3(double d) {
        NumberFormat nf = NumberFormat.getNumberInstance();
        // 保留3位小数
        nf.setMaximumFractionDigits(3);
        // 如果不需要四舍五入，可以使用RoundingMode.DOWN
        nf.setRoundingMode(RoundingMode.UP);
 
        return nf.format(d);
    }
	
	private String getFormattedData(String data){
        return RegexUtils.replaceStr(HtmlUtil.delHTMLTag(data), SepratorUtil.SEP_SPACE_EN,
                StringUtils.EMPTY);
    }
	
	
	/**
     * 分城数据爬取
     * @param page
     */
    private void cityProcess(Page page,Map<String, Object> extrasMap)
    {
    	
    	//下映当天日期
    	long offlineDate = Long.parseLong(extrasMap.get("offlineDate").toString());
    	
    	String rawText = page.getRawText();
		if(null == rawText || StringUtils.isBlank(rawText)){
			throw new SpiderException(SpiderExceptionCode.DataInvalideException);
		}
		JSONObject json = GsonUtils.fromJson(rawText,JSONObject.class);
		JSONArray jsonArray = json.getJSONObject("data").getJSONArray("detailList");
		if(jsonArray.size()==0 || jsonArray.isEmpty())
			throw new SpiderException(SpiderExceptionCode.DataInvalideException);
		
        List<MaoYanMovieCityModel> cityList = new ArrayList<>();
        String dataId = RegexUtils.regexSearch(RegexUtils.REGEX_INTEGER, page.getUrl().toString());
        if (StringUtils.isEmpty(dataId))
            throw new SpiderException(SpiderExceptionCode.DataInvalideException);
        for(int i = 0;i<jsonArray.size();i++){
        	JSONObject obj = (JSONObject) jsonArray.get(i);
            MaoYanMovieCityModel maoYanMovieCityModel = new MaoYanMovieCityModel(
            		null,
            		extrasMap.get("tvname").toString(),
            		dataId,
            		Constants.SiteName.MAOYAN,
            		obj.getString("name"),
            		obj.getString("boxInfo").replaceAll("[--]", "").equals("")?"":obj.getString("boxInfo"),
            		obj.getString("boxRate").replace("--", ""), 
            		obj.getString("showRate").replace("--", ""), 
            		obj.getString("avgShowView").replace("--", ""),
            		obj.getString("sumBoxInfo").replace("--", ""),
            		obj.getString("seatRate").replace("--", ""),
            		obj.getString("primeShowRate").replace("--", ""),
            		obj.getString("viewInfo").replace("--", ""),
                    obj.getString("showInfo").replace("--", ""));
            //下映当天日期
            maoYanMovieCityModel.setTimestamp(offlineDate);
            cityList.add(maoYanMovieCityModel);
        };

        page.putField(MaoYanMovieCityModel.class.getName(), cityList);
    }
	
    
    /** companyProcess(影投票房)   
	 * 创建人：张晓   
	 * 创建时间：2020年3月18日 下午4:14:37    
	 * 修改备注： 
	 * @param page
	 * @param extrasMap  
	 */
	private void companyProcess(Page page, Map<String, Object> extrasMap) {
		//下映当天日期
    	long offlineDate = Long.parseLong(extrasMap.get("offlineDate").toString());
    	
    	String rawText = page.getRawText();
		if(null == rawText || StringUtils.isBlank(rawText)){
			throw new SpiderException(SpiderExceptionCode.DataInvalideException);
		}
		JSONObject json = GsonUtils.fromJson(rawText,JSONObject.class);
		JSONArray jsonArray = json.getJSONObject("data").getJSONArray("detailList");
		if(jsonArray.size()==0 || jsonArray.isEmpty())
			throw new SpiderException(SpiderExceptionCode.DataInvalideException);
		List<MaoYanMovieShadowModel> shadowList = new ArrayList<MaoYanMovieShadowModel>();
        String dataId = RegexUtils.regexSearch(RegexUtils.REGEX_INTEGER, page.getUrl().toString());
        if (StringUtils.isEmpty(dataId))
            throw new SpiderException(SpiderExceptionCode.DataInvalideException);
        for(int i = 0;i<jsonArray.size();i++){
        	JSONObject obj = (JSONObject) jsonArray.get(i);
        	MaoYanMovieShadowModel maoYanMovieShadowModel = new MaoYanMovieShadowModel(
            		null,
            		extrasMap.get("tvname").toString(),
            		dataId,
            		Constants.SiteName.MAOYAN,
            		obj.getString("name"),
            		obj.getString("boxInfo").replaceAll("[--]", "").equals("")?"":obj.getString("boxInfo"),
            		obj.getString("boxRate").replace("--", ""), 
            		obj.getString("showRate").replace("--", ""), 
            		obj.getString("avgShowView").replace("--", ""),
            		obj.getString("sumBoxInfo").replace("--", ""),
            		obj.getString("seatRate").replace("--", ""),
            		obj.getString("primeShowRate").replace("--", ""),
            		obj.getString("viewInfo").replace("--", ""),
                    obj.getString("showInfo").replace("--", ""),
                    obj.getString("avgSeatView").replace("--", ""),
                    obj.getString("primeShow").replace("--", "")
                    );
            //下映当天日期
        	maoYanMovieShadowModel.setTimestamp(offlineDate);
        	shadowList.add(maoYanMovieShadowModel);
        };

        page.putField(MaoYanMovieShadowModel.class.getName(), shadowList);
		
	}
    
    
    private void peopleProcess(Page page,Map<String, Object> extrasMap)
    {
    	
    	long offlineAfterDate = Long.parseLong(extrasMap.get("offlineAfterDate").toString());
    	
        Html html = PageUtils.spiderAudienceRating(page,cookies);
        
        List<String> divList = html.xpath("//div[@class='stackcolumn']").all();
        if (divList == null || divList.isEmpty())
            throw new SpiderException(SpiderExceptionCode.DataInvalideException);

        List<String> ageNameList = html.xpath("//svg[@id='ageData']/g[@class='x']//text/text()")
                .all();
        ageNameList = clearSpaces(ageNameList);
        List<String> ageValueList = html.xpath
                ("//svg[@id='ageData']/g[@class='bar-group']//text/text()").all();
        ageValueList = clearSpaces(ageValueList);
        this.namesAndValuesValidate(ageNameList, ageValueList);
        //转换数据
        Map<String, List<String>> convertNamesAndValuesMap = convertNamesAndValues(ageNameList,ageValueList);
        ageNameList = convertNamesAndValuesMap.get("nameList");
        ageValueList = convertNamesAndValuesMap.get("valueList");
        
        
        String[][] sexData = this.getLineNamesAndValues(divList, "性别");
        String[][] eduData = this.getLineNamesAndValues(divList, "教育");

        List<String> areaNameList = html.xpath
                ("//section[@class='area-section']//div[@class='linebars-content']/div[2]/text()").all();
        areaNameList = clearSpaces(areaNameList);
        List<String> areaValueList = html.xpath
                ("//section[@class='area-section']//div[@class='linebars-content']//div[@class='linebars-value']/text()").all();
        areaValueList = clearSpaces(areaValueList);
        this.namesAndValuesValidate(areaNameList, areaValueList);
        //转换数据
        Map<String, List<String>> convertMap = convertNamesAndValues(areaNameList,areaValueList);
        areaNameList = convertMap.get("nameList");
        areaValueList = convertMap.get("valueList");
        
        String[][] occpData = this.getPieNamesAndValues(html, "occupData");
        String[][] labelData = this.getPieNamesAndValues(html, "interestData");

        String dataId = RegexUtils.regexSearch(RegexUtils.REGEX_INTEGER, page.getUrl().toString());
        MaoYanMoviePeopleModel maoYanMoviePeopleModel = new MaoYanMoviePeopleModel(
        		null,
        		extrasMap.get("tvname").toString(),
        		dataId, Constants
                .SiteName.MAOYAN, sexData[0], sexData[1], ageNameList.toArray(new
                String[ageNameList.size()]), ageValueList.toArray(new String[ageValueList.size()
                ]), eduData[0], eduData[1], areaNameList.toArray(new String[areaNameList.size()])
                , areaValueList.toArray(new String[areaValueList.size()]), occpData[0],
                occpData[1], labelData[0], labelData[1]);
        //下映后一天数据
        maoYanMoviePeopleModel.setTimestamp(offlineAfterDate);
        page.putField(MaoYanMoviePeopleModel.class.getName(), maoYanMoviePeopleModel);
    }
    
    
    private Map<String,List<String>> convertNamesAndValues(List<String> nameList,List<String> valueList){
    	Map<String,List<String>> dataMap = new HashMap<String,List<String>>();
    	String[] returnNameArr = new String[nameList.size()];
    	String[] returnValueArr = new String[valueList.size()];
    	for(int i=0;i<nameList.size();i++){
    		if(nameList.get(i).contains("二线城市")){
    			returnNameArr[0] = nameList.get(i);
    			returnValueArr[0] = valueList.get(i);
        	}
        	else if(nameList.get(i).contains("四线城市")){
        		returnNameArr[1] = nameList.get(i);
    			returnValueArr[1] = valueList.get(i);
        	}
        	else if(nameList.get(i).contains("三线城市")){
        		returnNameArr[2] = nameList.get(i);
    			returnValueArr[2] = valueList.get(i);
        	}
        	else if(nameList.get(i).contains("一线城市")){
        		returnNameArr[3] = nameList.get(i);
    			returnValueArr[3] = valueList.get(i);
        	}
        	else if(nameList.get(i).contains("白领")){
        		returnNameArr[0] = nameList.get(i);
    			returnValueArr[0] = valueList.get(i);
        	}
        	else if(nameList.get(i).contains("其他")){
        		returnNameArr[1] = nameList.get(i);
    			returnValueArr[1] = valueList.get(i);
        	}
        	else if(nameList.get(i).contains("学生")){
        		returnNameArr[2] = nameList.get(i);
    			returnValueArr[2] = valueList.get(i);
        	}
        	else if(nameList.get(i).contains("20岁以下")){
        		returnNameArr[0] = nameList.get(i);
    			returnValueArr[0] = valueList.get(i);
        	}else if(nameList.get(i).contains("20~24")){
        		returnNameArr[1] = nameList.get(i);
    			returnValueArr[1] = valueList.get(i);
        	}else if(nameList.get(i).contains("25~29")){
        		returnNameArr[2] = nameList.get(i);
    			returnValueArr[2] = valueList.get(i);
        	}else if(nameList.get(i).contains("30~34")){
        		returnNameArr[3] = nameList.get(i);
    			returnValueArr[3] = valueList.get(i);
        	}else if(nameList.get(i).contains("35~39")){
        		returnNameArr[4] = nameList.get(i);
    			returnValueArr[4] = valueList.get(i);
        	}else if(nameList.get(i).contains("40岁以上")){
        		returnNameArr[5] = nameList.get(i);
    			returnValueArr[5] = valueList.get(i);
        	}
    	}
    	
    	dataMap.put("nameList", Arrays.asList(returnNameArr));
    	dataMap.put("valueList", Arrays.asList(returnValueArr));
    	return dataMap;
    	
    }
    
    
    private String[][] getPieNamesAndValues(Html html, String tagId)
    {
        List<String> occpList = html.xpath("//svg[@id='" + tagId +
                "']/path[@class='pie-item']/@data-info").all();
        if (occpList == null || occpList.isEmpty())
            throw new SpiderException(SpiderExceptionCode.DataInvalideException);
        List<String> occpNameList = occpList.stream().filter(data -> data.split(";").length > 1)
                .map(data -> data.split(";")[1]).collect(Collectors.toList());
        List<String> occpValueList = occpList.stream().filter(data -> data.split(";").length > 1)
                .map(data -> data.split(";")[0]).collect(Collectors.toList());
        this.namesAndValuesValidate(occpNameList, occpValueList);
        if(tagId.equals("occupData")){
        	//转换数据
            Map<String, List<String>> convertNamesAndValuesMap = convertNamesAndValues(occpNameList,occpValueList);
            occpNameList = convertNamesAndValuesMap.get("nameList");
            occpValueList = convertNamesAndValuesMap.get("valueList");
        }
        return new String[][]{occpNameList.toArray(new String[occpNameList.size()]),
                occpValueList.toArray(new String[occpValueList.size()])};
    }

    private String[][] getLineNamesAndValues(List<String> divList, String type)
    {
        String sexDiv = divList.stream().filter(divStr -> divStr.contains(type)).findFirst().get();
        if (StringUtils.isEmpty(sexDiv))
            throw new SpiderException(SpiderExceptionCode.DataInvalideException);
        Html sexHtml = new Html(sexDiv);
        List<String> nameList = sexHtml.xpath("//span[@class='stackcolumn-desc-text']/text()")
                .all();
        List<String> valueList = sexHtml.xpath("//i[@class='cs']/text()").all();
        this.namesAndValuesValidate(nameList, valueList);
        if(type.contains("性别")||type.contains("教育")){
        	String[] returnNameArr = new String[nameList.size()];
        	String[] returnValueArr = new String[valueList.size()];
        	for(int i = 0;i<nameList.size();i++){
            	
            	if(nameList.get(i).contains("男")){
            		returnNameArr[0] = nameList.get(i);
        			returnValueArr[0] = valueList.get(i);
            	}
            	else if(nameList.get(i).contains("女")){
            		returnNameArr[1] = nameList.get(i);
        			returnValueArr[1] = valueList.get(i);
            	}
            	else if(nameList.get(i).contains("本科及以上")){
            		returnNameArr[0] = nameList.get(i);
        			returnValueArr[0] = valueList.get(i);
            	}
            	else if(nameList.get(i).contains("本科以下")){
            		returnNameArr[1] = nameList.get(i);
        			returnValueArr[1] = valueList.get(i);
            	}
            }
        	nameList = Arrays.asList(returnNameArr);
        	valueList = Arrays.asList(returnValueArr);
        }
        valueList = valueList.stream().map(value -> value + "%").collect(Collectors.toList());
        return new String[][]{nameList.toArray(new String[nameList.size()]), valueList.toArray(new
                String[valueList.size()])};
    }

    private void namesAndValuesValidate(List<String> nameList, List<String> valueList)
    {
        if (nameList == null || nameList.isEmpty())
            throw new SpiderException(SpiderExceptionCode.DataInvalideException);
        if (valueList == null || valueList.isEmpty() || nameList.size() != valueList.size())
            throw new SpiderException(SpiderExceptionCode.DataInvalideException);
    }
    
	private List<String> clearSpaces(List<String> paramlist){
    	List<String> newList = new ArrayList<String>(paramlist.size());
    	for(String str : paramlist){
    		newList.add(str.trim());
    	}
    	return newList;
    }
    
	private void marketProcess(Page page,Map<String, Object> extrasMap)
    {
		//下映后一天
		long offlineAfterDate = Long.parseLong(extrasMap.get("offlineAfterDate").toString());
		
		String tvname = extrasMap.get("tvname").toString();
		
        List<String> divList = page.getHtml().xpath("//div[@class='trace-main']").all();
        if (divList == null || divList.isEmpty())
            throw new SpiderException(SpiderExceptionCode.DataInvalideException);
        List<MaoYanMovieMarketModel> marketList = new ArrayList<>(divList.size());
        String dataId = RegexUtils.regexSearch(RegexUtils.REGEX_INTEGER, page.getUrl().toString());
        
        for(String divStr : divList){
        	Html html = new Html(divStr);
            MaoYanMovieMarketModel maoYanMovieMarketModel = new MaoYanMovieMarketModel(
            		null,
            		tvname,
            		dataId, Constants.SiteName.MAOYAN, 
            		StringUtil.delSpecialCharacters(html.xpath("//span[@class='trace-name flex-item']/text()").get()),
            		StringUtil.delSpecialCharacters(html.xpath("//span[@class='date-str']/text()").get()),
            		StringUtil.delSpecialCharacters(html.xpath("//p[@class='trace-content']/text()").get()),
            		StringUtil.delSpecialCharacters(html.xpath("//span[@class='trace-tip flex-item']/em/text()").get()),
            		StringUtil.delSpecialCharacters(html.xpath("//span[@class='date-desc']/text()").get())
            		);
            maoYanMovieMarketModel.setTimestamp(offlineAfterDate);
            marketList.add(maoYanMovieMarketModel);
    	}
        page.putField(MaoYanMovieMarketModel.class.getName(), marketList);
    }
    
    //保存昨日播放量
  	@SuppressWarnings("unchecked")
  	public void yestodayProcess(Page page){
  		
		String json = page.getRawText();
	    if (StringUtils.isEmpty(json))
	        throw new SpiderException(SpiderExceptionCode.DataInvalideException);
	    Map<String, Object> map = GsonUtils.fromJson(json, Map.class);
	    if (map == null || map.isEmpty() || map.get("movieList") == null)
	        throw new SpiderException(SpiderExceptionCode.DataInvalideException);
		Map<String, Object> dataMap = ((Map<String, Object>) map.get("movieList"));
		List<Map<String, Object>> movList = (List<Map<String, Object>>) dataMap.get("list");
	    if (movList == null || movList.isEmpty())
	            throw new SpiderException(SpiderExceptionCode.DataInvalideException);
	        //this.getMovieExistList(movList);  
			List<MaoYanBoxofficeModel> list = new ArrayList<>();
		      movList.forEach(movMap ->
		      {

				  Map<String, Object> movieInfo = (Map<String, Object>) movMap.get("movieInfo");
				  String dataId = RegexUtils.regexSearch(RegexUtils.REGEX_INTEGER, StringUtil
						  .nullToString(movieInfo.get("movieId")));
				  Map<String, Object> boxSplitUnit = (Map<String, Object>) movMap.get("boxSplitUnit");
				  String box = StringUtil.nullToString(boxSplitUnit.get("num"))+StringUtil.nullToString(boxSplitUnit.get("unit"));

				  String releaseDateCount = RegexUtils.regexSearch(RegexUtils.REGEX_INTEGER, StringUtil
						  .nullToString(movieInfo.get("releaseInfo")));
				  String queryDate = DateUtils.getBeforeDayDynamic(new Date(),1);

		          MaoYanBoxofficeModel maoYanBoxofficeModel = new MaoYanBoxofficeModel(UUIDUtils.getId(),
				  null,
				  StringUtil.nullToString(movieInfo.get("movieName")),
				  StringUtil.nullToString(box), // 当日票房
				  StringUtil.nullToString(movMap.get("sumBoxDesc")).replace("--", ""), // 总票房
				  StringUtil.nullToString(movMap.get("showCountRate")).replace("--", ""), // 排片比
				  StringUtil.nullToString(movMap.get("boxRate")).replace("--", ""), // 票房百分比
				  StringUtil.nullToString(movMap.get("showCount")).replace("--", ""), // 当日场次
				  StringUtil.nullToString(releaseDateCount), // 上映天数
				  StringUtil.nullToString(queryDate).replace("--", ""), // 上映日期
				  StringUtil.nullToString(movMap.get("avgSeatView")).replace("--", ""), // 上座率
				  StringUtil.nullToString(movMap.get("avgShowView")).replace("--", ""), // 场均人次
				  StringUtil.nullToString(null), // 排座占比
				  Constants.SiteName.MAOYAN, //网站名称
				  dataId,
				  DateUtils.getSpecifiedDayBeforeDate(DateUtils.getDateString(new Date(), DateUtils
						.DAY_FORMAT),DateUtils.SECONDS_FORMAT));//网站电影id



		          maoYanBoxofficeModel.setRedisKey(dataId);	
		          list.add(maoYanBoxofficeModel);
		      });
        page.putField(MaoYanBoxofficeModel.class.getName(), list);
          
  	}
    
	@Override
	protected String[] getStartRequestUrls() {
		return new String[]{START_URL};
	}

	@Override
	protected String getSpiderType() {
		return Constants.SpiderTaskType.MOVIE_BOXOFFICE;
	}

	@Override
	public String getPageDataType(Page page) {
		String url = page.getUrl().toString();
        if (url.contains("type=areaBox&method=change"))
            return Constants.PageDataType.TV_CITY;
        if (url.contains("type=shadowBox&method=change"))
            return Constants.PageDataType.MOVIE_COMPANY;
        if (url.contains("/wantindex"))
            return Constants.PageDataType.TV_AUDIENCE;
        if (url.contains("_v_=yes"))
            return Constants.PageDataType.TV_RECORD;
        if (url.contains("/marketing"))
            return Constants.PageDataType.MOVIE_MARKET;
        if (url.contains("/audienceRating"))
            return Constants.PageDataType.TV_COMMENT;
        if (url.contains("/boxshow"))
        	return Constants.PageDataType.MOVIE_BOX_DETAIL;
        if (url.contains("/trailers"))
        	return Constants.PageDataType.MOVIE_MATERIELS;
        if (url.contains("/dashboard-ajax"))
        	return Constants.PageDataType.MOVIE_BOX;
        return Constants.PageDataType.SEARCH_LIST;
	}
	
	
	@SuppressWarnings("unchecked")
	public void getMovieOffLineList(){
		try {
			int availableProcessors = Runtime.getRuntime().availableProcessors();
	    	ExecutorService threadPool = Executors.newFixedThreadPool(availableProcessors>1?availableProcessors:1);
	    	Future<Object> submit = threadPool.submit(new DataClass());
			if(null == offLineList){
				synchronized (this){
					if(null == offLineList){
						offLineList = new ArrayList<Object>((List<Object>) submit.get());
					}
				}
			}
			threadPool.shutdown();
		} catch (InterruptedException e) {
			e.printStackTrace();
		} catch (ExecutionException e) {
			e.printStackTrace();
		}
	}
	
	
	public void getMovieExistList(List<Map<String, Object>> movList){
		try {
			int availableProcessors = Runtime.getRuntime().availableProcessors();
	    	ExecutorService threadPool = Executors.newFixedThreadPool(availableProcessors>1?availableProcessors:1);
	    	ExistClass existClass = new ExistClass(movList);
	    	Future<Object> submit = threadPool.submit(existClass);
			if(null == existMap){
				synchronized (this){
					if(null == existMap){
						existMap = submit.get();
					}
				}
			}
			threadPool.shutdown();
		} catch (InterruptedException e) {
			e.printStackTrace();
		} catch (ExecutionException e) {
			e.printStackTrace();
		}
	}
	
	public class DataClass implements Callable<Object>{
		@Override
		public Object call() throws Exception {
			return maoYanMovieBasicInfoService.queryMovieOffLineListByRecordLineTable();
		}
		
	}
	
	
	public class ExistClass extends DataClass {
		
		private List<Map<String, Object>> movList = new ArrayList<Map<String, Object>>();
		
		@Override
		public Object call() throws Exception {
			return maoYanMovieBasicInfoService.queryMovieExistList(movList);
		}
		
		public ExistClass(List<Map<String, Object>> movList){
			this.movList = movList;
		}
		
		public ExistClass(){
			
		}
		
	}
	
	@SuppressWarnings({ "unused"})
	private String getStarLevel(List<String> list){
		Double starLevel = 0.0;
		if(list == null || list.size()<0)
		return null;
		for(String str: list){
			if(str.contains("fullstar")){
				starLevel +=1; 
			}else if(str.contains("halfstar")){
				starLevel+=0.5;
			}
		}
		return starLevel+"";
	}
	
	private String convertDateStr(String str){
    	String first = str.substring(0,4);
    	String second = str.substring(4, 6);
    	String three = str.substring(6);
    	return first+"-"+second+"-"+three;
    }
	
	
	public String convertDateToDate(String str){
		
		SimpleDateFormat sdf=new SimpleDateFormat("HH:mm:ss");
    	String first = str.substring(0,4);
    	String second = str.substring(4, 6);
    	String three = str.substring(6);
    	return first+"-"+second+"-"+three+" "+sdf.format(new Date());
    }
	
	//将指定日期转化为秒数
    public long getSecondsFromDate(String expireDate){
        if(expireDate==null)
            return 0;
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date=null;
        try{
            date=sdf.parse(expireDate);
            return (long)(date.getTime());
            }
        catch(ParseException e)
        {
            e.printStackTrace();
            return 0;
            }
        }
	
}
